package vtc;

import java.util.concurrent.*;
import java.io.*;

// One single input queue and one single output queue

abstract class FunctionalUnit extends VtcUnit 
{
	protected VtcTimeTaggedEvent inValue_;
	protected VtcTimeTaggedEvent outValue_;
	
	FunctionalUnit(String id, VtcArrayBlockingQueue inQueues[], VtcArrayBlockingQueue outQueues[]) 
	{
		super(id, inQueues, outQueues);
		inValue_ = null;
		outValue_ = null;
	}
	
	abstract public void functionalProcess() throws InterruptedException;
		
	public void process() throws InterruptedException
	{
		inValue_ = inQueues_[0].take();
		this.functionalProcess();
		if(outValue_ != null)
		{
			outQueues_[0].forcePut(outValue_);
			outValue_ = null;
		}
	}
}